# coding=utf-8
import os


def get_db_uri(dbinfo):
    engine = dbinfo.get("ENGINE", "sqlite")
    driver = dbinfo.get("DRIVER", "sqlite")
    user = dbinfo.get("USER", "")
    password = dbinfo.get("PASSWORD", "")
    host = dbinfo.get("HOST", "")
    port = dbinfo.get("PORT", "")
    database = dbinfo.get("DATABASE", "sqlite.db")
    return "{}+{}://{}:{}@{}:{}/{}".format(engine, driver, user, password, host, port, database)


class Config():
    DEBUG = False
    TESTING = False

    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_DATABASE_URI = "sqlite+sqlite:///sqlite.db"
    REDIS_URL = "redis://:password@localhost:6379/0"

    # 开启session
    # SECRET_KEY = "session use"


class DefaultConfig(Config):
    DEBUG = True


class DevelopConfig(Config):
    DEBUG = True

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "root",
        "HOST": "mysql",  # 容器服务名称  192.168.1.125
        "PORT": 3306,
        "DATABASE": "bluetooth"
    }
    REDIS_URL = "redis://redis:6379/0"  # 第二个 docker 容器 redis 服务名称
    MONGO_URI = "mongodb://mongodb:27017/ibeacon"  # 第二个 docker 容器 mongodb 服务名称

    SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)


# 项目根目录
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
envs = {
    "default": DefaultConfig,
    "develop": DevelopConfig
}
